
<%@ page import="coe.pumbaa.Post" %>
<%@ page import="coe.pumbaa.Category" %>
<% def stringManagerService = application.getAttribute("org.codehaus.groovy.grails.APPLICATION_CONTEXT").getBean("stringManagerService") %>
<% def springSecurityService = application.getAttribute("org.codehaus.groovy.grails.APPLICATION_CONTEXT").getBean("springSecurityService") %>
<!doctype html>
<html>
  <head>
    <meta name="layout" content="PumbaaLayout">
  <g:set var="entityName" value="${message(code: 'category.label', default: 'Category')}" />
  <title>Category ${catInstance.title}</title>
</head>
<body>
  <section id="main" class="column">
    <pumbaa:alert />
    <article class="module width_full">
      <header><h3>Category : ${catInstance.title}</h3></header>
      <table class="tablesorter" cellspacing="0" style="width:100%;">
        <thead>
          <tr>
            <th>Title</th>
            <th style="width: 50px;">likes</th>
            <th style="width: 200px;">Date</th>
        <g:if test="${springSecurityService.isLoggedIn()}">
          <th style="width: 110px;">Actions</th>
        </g:if>
        </tr>
        </thead>
        <tbody>
        <g:each in="${postInstanceList}" var="post">
          <tr>
            <td><g:link controller="comment" action="list" id="${post.id}">${stringManagerService.stringToHTML(post.title)}</g:link></td>
          <td>${stringManagerService.countMemberInString(post?.likes)}</td>
          <td><g:formatDate format="dd/MM/yyyy ( HH:mm:ss )" date="${post.timestamp}"/></td>
          <g:if test="${springSecurityService.isLoggedIn()}">
            <td>
              <table id="show_action"><tr>
                  <td style="width: 25px;">
                    <div id="show_subscribe${post.id}">
                      <g:render template="subscribe" model="['postInstance':post,'role':roleUser]"/>
                    </div>
                  </td>
                <g:render template="action" model="['post':post]"/>
                </tr></table>
            </td>
          </g:if>
          </tr>
        </g:each>
        </tbody>
      </table>
      <footer>
        <div class="pagination">
          <h4><g:paginate id="${catInstance.id}" total="${postInstanceTotal}" /></h4>
        </div>
      </footer>
    </article>
    <g:if test="${stringManagerService.checkObjectInString(roleUser,catInstance.allowPost)}">
    <article class="module width_full">
      <header><h3>Crate post</h3></header>
      <g:form name="postForm" action="save" method="POST">
        <input type="hidden" name="catID" value="${catInstance.id}"/>
        <div class="module_content">
          <g:render template="form"/>
          <div class="submit_link">
            <g:submitButton class="alt_btn" name="submit" value="Create"/>
          </div>
        </div>
        <div class="clear"></div>
      </g:form>
    </article>
    </g:if>
    <div class="spacer"></div>
  </section>
</body>
</html>
